// SPDX-FileCopyrightText: 2023 CitruS Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

package com.fanwj.citrus.utils

import android.os.Build
import android.os.RemoteException
import com.fanwj.citrus.Backend

object Log {
    // Tracks whether we should share the old log or the current log
    var gameLaunched = false

    fun debug(message: String) {
        try {
            Backend.stub.Log_debug(message)
        } catch (e: RemoteException) {
            Backend.handleException(e)
        }
    }

    fun warning(message: String) {
        try {
            Backend.stub.Log_warning(message)
        } catch (e: RemoteException) {
            Backend.handleException(e)
        }
    }

    fun info(message: String) {
        try {
            Backend.stub.Log_info(message)
        } catch (e: RemoteException) {
            Backend.handleException(e)
        }
    }

    fun error(message: String) {
        try {
            Backend.stub.Log_error(message)
        } catch (e: RemoteException) {
            Backend.handleException(e)
        }
    }

    fun critical(message: String) {
        try {
            Backend.stub.Log_critical(message)
        } catch (e: RemoteException) {
            Backend.handleException(e)
        }
    }

    fun logDeviceInfo() {
        info("Device Manufacturer - ${Build.MANUFACTURER}")
        info("Device Model - ${Build.MODEL}")
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
            info("SoC Manufacturer - ${Build.SOC_MANUFACTURER}")
            info("SoC Model - ${Build.SOC_MODEL}")
        }
        info("Total System Memory - ${MemoryUtil.getDeviceRAM()}")
    }
}
